package com.sam.im.sms.util;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 描述
 * liuyucheng
 * Created By 刘育成 on 2019/5/31.
 */
public class Utils {
    /**
     * 保存多语言设置
     */
    public static String saveLanguage(Context context, String language , int type){//1  为存  2  为取
        SharedPreferences mySharePreferences = context.getSharedPreferences("myshare", Activity.MODE_PRIVATE);
        //实例化SharedPreferences.Editor对象
        SharedPreferences.Editor editor = mySharePreferences.edit();
        if (type==1){
            editor.putString("language",language);
            editor.commit();
            return "" ;
        }else {
            return mySharePreferences.getString("language","zh_cn");

        }
    }
    /**
     * 去掉手机号内除数字外的所有字符
     *
     * @param str 手机号
     * @return
     */
    public static String formatNumber(String str){
        String regex = "(\\+86)|[^0-9]";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.replaceAll(" ");
    }
}
